package testes;

import org.junit.*;

import agenda.*;
import excecoes.*;

public class EmailTest {

        Email email;
       
        @Before
        public void setUp() throws Exception {
                email = new Email("ois@soufofo.com");
        }
       
        @Test
        public void testValidaEndereco1() throws Exception {
                try {
                        email = new Email("anything@gmail.com");
                        email = new Email("abc@bla.com.br");
                } catch (EmailInvalido e) {
                        Assert.fail("Nao devo chegar aqui.");
                }
        }
       
        @Test
        public void testValidaEndereco2() throws Exception {
               
                //verifica a excecao no caso de haver caracteres invalidos apos o '@'
                try {
                        email = new Email("dugs@gmail.231.com");
                }
                catch(EmailInvalido e) {
                        Assert.assertEquals("E-mail invalido.", e.getMessage());                        
                }
               
                try {
                        email = new Email("qqq@gmail$.com");
                }
                catch(EmailInvalido e) {
                        Assert.assertEquals("E-mail invalido.", e.getMessage());
                }
               
                try {
                        email = new Email("qqq@gmailcom");
                }
                catch(EmailInvalido e) {
                        Assert.assertEquals("E-mail invalido.", e.getMessage());
                }
               
                try {
                        email = new Email("qqqgmail.com");
                }
                catch(EmailInvalido e){
                        Assert.assertEquals("E-mail invalido.", e.getMessage());
                }
               
               
        }
       
}

